#!/bin/bash
#UBuntu初始化脚本
#####################################################
#1，开启root远程登录。
#2，系统语言、系统时区、时间同步、关闭系统更新。
#3，安装常用工具
#####################################################

echo "########################################################"
echo "  1,    \033[33m请用root用户执行此脚本\033[0m"           
echo "  2,    在\033[32mUbuntu 20.04.2 LTS\033[0m上可以运行"   
echo "  3,    最后编辑：2021年9月30日10点25分"                
echo "########################################################"

#1：
apt update
echo "\033[33mROOT远程登陆\033[0m"
apt -y install openssh-server
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sed -i 's/#Port 22/Port 22/g' /etc/ssh/sshd_config
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
systemctl restart sshd

#2：
echo "\033[33m中文语言包、时区、时间和关闭系统更新\033[0m"
apt -y install language-pack-zh-han*
echo "
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh"
" > /etc/default/locale
timedatectl set-timezone "Asia/Shanghai"
apt -y install ntpdate
ntpdate time.windows.com

cp /etc/apt/apt.conf.d/10periodic /etc/apt/apt.conf.d/10periodic.bak
echo "APT::Periodic::Update-Package-Lists \"0\";
APT::Periodic::Download-Upgradeable-Packages \"0\";
APT::Periodic::AutocleanInterval \"0\";
APT::Periodic::Unattended-Upgrade \"0\";
" > /etc/apt/apt.conf.d/10periodic

#3:
echo "\033[33m安装常用工具\033[0m"
apt -y install net-tools tree expect curl 

#重启对话框
if (whiptail --title "Reboot" --yesno "Yes - Reboot \n No - Exit" 10 60) then
    reboot
else
    exit
fi